CapitalGainBuy

class CapitalGainBuy(_account: Account, val dateInt: Int, val totalAmount: Long, val sharesPurchased: Long) : Comparable<CapitalGainBuy>

Tracks a buy transaction for capital gain calculations, particularly average cost with long term and short term gains. Per U.S. IRS Publication 564, single-category average cost allocates to the earliest shares acquired first:

Even though you include all unsold shares of a fund in a single category to compute average basis, you may have both short-term and long-term gains or losses when you sell these shares. To determine your holding period, the shares disposed of are considered to be those acquired first.
*

This class tracks how many shares of a particular buy transaction has already been allotted by one or more sale transactions, and also helps track the remaining average cost basis. Note that these objects should always be processed in date order. If the date provided to methods CapitalGainBuy.allot, CapitalGainBuy.getRemainingShares or CapitalGainBuy.setRemainingBasis were ever to go backwards in time, this could give incorrect results because of stock splits.

Constructors

Link copied to clipboard
constructor(_account: Account, dateInt: Int, totalAmount: Long, sharesPurchased: Long)

Properties

Link copied to clipboard

The date of the buy transaction.

Link copied to clipboard
Link copied to clipboard

The remaining basis after the most recently-processed sale transaction.

Link copied to clipboard

The number of shares purchased in the buy transaction.

Link copied to clipboard

The total buy amount, in the investment account's currency (dollars, euro, etc.).

Functions

Link copied to clipboard
fun allot(sharesRequested: Long, asofDate: Int): Long

Allocate the requested number of shares from the total amount, if possible.

Link copied to clipboard
open operator override fun compareTo(other: CapitalGainBuy): Int
Link copied to clipboard
fun getRemainingShares(asofDate: Int): Long

Compute the remaining shares for a buy transaction

Link copied to clipboard
fun setRemainingBasis(averageCost: Double, asofDate: Int)

Compute the remaining basis for this buy transaction, given a particular average cost.

Link copied to clipboard
open override fun toString(): String